<!--
 * @Author: your name
 * @Date: 2021-09-23 14:31:14
 * @LastEditTime: 2021-10-09 13:43:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \dashboardConfiguration\src\views\main-sidebar-sub-menu.vue
-->
<template>
  <el-submenu
    v-if="menu.children && menu.children.length >= 1"
    :index="menu.menuLogicId + ''"
    :popper-class="'site-sidebar--' + sidebarLayoutSkin + '-popper'"
  >
    <template slot="title">
      <icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon" />
      <span>{{ menu.menuName }}</span>
    </template>
    <sub-menu v-for="item in menu.children" :key="item.menuLogicId" :menu="item" :dynamic-menu-routes="dynamicMenuRoutes" />
  </el-submenu>
  <el-menu-item v-else :index="menu.menuLogicId + ''" @click="gotoRouteHandle(menu)">
    <icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon" />
    <span>{{ menu.menuName }}</span>
  </el-menu-item>
</template>

<script>
import SubMenu from './main-sidebar-sub-menu'
export default {
  name: 'SubMenu',
  components: {
    SubMenu
  },
  props: {
    menu: {
      type: Object,
      required: true
    },
    dynamicMenuRoutes: {
      type: Array,
      required: true
    }
  },
  computed: {
    sidebarLayoutSkin: {
      get() {
        return this.$store.state.common.sidebarLayoutSkin
      }
    }
  },
  methods: {
    // 通过menuId与动态(菜单)路由进行匹配跳转至指定路由
    gotoRouteHandle(menu) {
      var route = this.dynamicMenuRoutes.filter(item => item.meta.menuId === menu.menuLogicId)
      if (route.length >= 1) {
        this.$router
          .push({
            name: route[0].name,
            query: { number: menu.menuLogicId, title: menu.menuName }
          })
          .catch(err => {
            console.log(err)
          })
      }
    }
  }
}
</script>
